| Conditions | 2 |
| Total Lines | 18 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { useEffect } from "react"; |
||
| 10 | |||
| 11 | // eslint-disable-next-line import/prefer-default-export |
||
| 12 | export function useLoadClassifications( |
||
| 13 | dispatch: DispatchType, |
||
| 14 | ): { |
||
| 15 | classifications: Classification[]; |
||
| 16 | isLoadingClassifications: boolean; |
||
| 17 | } { |
||
| 18 | const classifications = useSelector(getClassifications); |
||
| 19 | const isLoading = useSelector(classificationsIsLoading); |
||
| 20 | |||
| 21 | useEffect((): void => { |
||
| 22 | if (classifications.length === 0 && !isLoading) { |
||
| 23 | dispatch(loadClassificationsIntoState()); |
||
| 24 | } |
||
| 25 | }, [classifications.length, isLoading, dispatch]); |
||
| 26 | |||
| 27 | return { classifications, isLoadingClassifications: isLoading }; |
||
| 28 | } |
||
| 29 |